package com.limao.CacheManager;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;

import com.Hazelcast.Cache;
import com.Hazelcast.CacheFactory;
import com.limao.DBDataClass.SysIceBuyAutoDataClass;
import com.limao.DBProvider.SysIceBuyAutoProvider;
import com.limao.cache.BasicModule;
;

public class BuyIceTaskCacheManager extends BasicModule{
	
	private static BuyIceTaskCacheManager instance;
	
	public static BuyIceTaskCacheManager getInstance() {
        return instance;
    }
	SysIceBuyAutoProvider provider;
    
    private Cache<String, SysIceBuyAutoDataClass> taskCacheForBuyUnice;
	
	public BuyIceTaskCacheManager() {
		super("BuyIceTaskCacheManager");
		taskCacheForBuyUnice= CacheFactory.createCache("cd_taskCacheForBuyUnice");

		initProvider();
	}
	
    @Override
	public void initialize() {
        super.initialize();
        instance=this;
    }
    
    
    //冻结购物收益自动解冻 　清除
    public  void ClearTaskForBuyUnice()
    {
    	taskCacheForBuyUnice.clear();
    }
    
    
    public ArrayList<SysIceBuyAutoDataClass> Load_TaskForBuyUnice()
    {
    	ArrayList<SysIceBuyAutoDataClass> list=new ArrayList<SysIceBuyAutoDataClass>();
    	if(taskCacheForBuyUnice.size()>0)
    	{
	        Set set =taskCacheForBuyUnice.keySet();
	    	Iterator it=set.iterator();
	    	while(it.hasNext()){
	     		String s= (String) it.next();
	    		list.add(taskCacheForBuyUnice.get(s));
	    	}
    	}
    	
    	if(list.size()==0)
    	{
    		list=provider.Load_IceBuyAuto_All();
    		if(list!=null)
    		{
    			for(SysIceBuyAutoDataClass obj:list)
    			{
    				taskCacheForBuyUnice.put(obj.paramid,obj);
    			}
    		}
    	}
    	
    	return list;
    }
    
    
    //**************************************************************************
    private void initProvider() {
        if (provider == null ) {
            try {
                provider =SysIceBuyAutoProvider.getInstance();
                
            }
            catch (Exception e) {
            	e.printStackTrace();
            }
        }
    }
    
}
